#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e6+100;
typedef long long LL;
LL fa[maxn];
LL find(LL x){
    if(fa[x]!=x) return fa[x]=find(fa[x]);
    else return fa[x];
}
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL n,m;cin>>n>>m;
  for(LL i=1;i<=n;i++) fa[i]=i;
  for(LL i=1;i<=m;i++){
    LL u,v;cin>>u>>v;
    if(find(u)!=find(v)){
        fa[find(u)]=find(v);
    }
  }
  LL ans=0;
  for(LL i=1;i<=n;i++){
    if(fa[i]==i) ans++;
  }
  cout<<ans<<endl;
return 0;
}
